package activity.addCamera.adapter;


import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hichip.campro.R;
import com.hichip.content.HiChipDefines;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by lt on 2018\3\9 0009.
 */

public class WiFiListDevAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private String[] videoApenc;
    private List<HiChipDefines.SWifiAp> wifi_list = Collections.synchronizedList(new ArrayList<HiChipDefines.SWifiAp>());

    public WiFiListDevAdapter(Context context, List<HiChipDefines.SWifiAp> wifi_list) {
        this.mInflater = LayoutInflater.from(context);
        this.wifi_list=wifi_list;
        videoApenc = context.getResources().getStringArray(R.array.video_apenc);
    }

    @Override
    public int getCount() {
        return wifi_list.size();
    }

    @Override
    public Object getItem(int position) {
        return wifi_list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("InflateParams")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HiChipDefines.SWifiAp wifi = wifi_list.get(position);
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_setting_wifi, null);
            holder = new ViewHolder();
            holder.txt_ssid = (TextView) convertView.findViewById(R.id.wifi_setting_item_ssid);
            holder.txt_safety = (TextView) convertView.findViewById(R.id.wifi_setting_item_safety);
            holder.txt_intensity = (TextView) convertView.findViewById(R.id.wifi_setting_item_signal_intensity);
            // holder.txt_state=(TextView)convertView.findViewById(R.id.wifi_setting_item_state);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (holder != null) {
            try {
                holder.txt_ssid.setText(new String(wifi.strSSID, "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            // holder.txt_ssid.setText(Packet.getString(icon_wifi.strSSID));
            holder.txt_safety.setText(videoApenc[wifi.EncType]);
            String strSignal = wifi.Signal + "" + "%";
            holder.txt_intensity.setText(strSignal);
        }

        return convertView;

    }

    public final class ViewHolder {
        public TextView txt_ssid;
        public TextView txt_safety;
        public TextView txt_intensity;
        // public TextView txt_state;
    }

}